package <%= repositoryPackageName %>;

import <%= domainPackageName %>.<%= camelCaseName(tableName,true) %>;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

/**
* <%= camelCaseName(tableName,true) %> <%=tableComment %> Repository
*
* @author 代码生成器@zhangQ
* @date <%= formatTime() %>
*/
@Repository
public interface <%= camelCaseName(tableName,true) %>Repository extends JpaRepository<<%= camelCaseName(tableName,true) %>, <%= table.primaryKeys[0].type %>>, JpaSpecificationExecutor<<%= camelCaseName(tableName,true) %>>  {
    /**
    * 根据主键查询实体
    *
    * @param <%= table.primaryKeys[0].name %>
    * @return
    */
    <%= camelCaseName(tableName,true) %> findBy<%= firstUpperCase(table.primaryKeys[0].name) %>Equals(<%= table.primaryKeys[0].type %> <%= table.primaryKeys[0].name %>);

    /**
    * 根据主键删除实体
    *
    * @param <%= table.primaryKeys[0].name %>
    * @return
    */
    @Modifying
    @Query("delete from <%= camelCaseName(tableName,true) %> t where t.<%= table.primaryKeys[0].name %> = ?1")
    int deleteBy<%= firstUpperCase(table.primaryKeys[0].name) %>Equals(<%= table.primaryKeys[0].type %> <%=  table.primaryKeys[0].name %>);

<% if(existsField(table.columns,'state')) { -%>
    /**
    * 修改状态
    *
    * @param <%= table.primaryKeys[0].name %>
    * @return
    */
    @Modifying
    @Query("update <%= camelCaseName(tableName,true) %> t set t.state=?2 where t.<%= table.primaryKeys[0].name %> = ?1")
    Integer updateByState(<%= table.primaryKeys[0].type %> <%=  table.primaryKeys[0].name %>,Integer state);
<% } -%>

}
